//
//  PlayerViewController.m
//  MountEverestFM
//
//  Created by dllo on 15/10/29.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "PlayerViewController.h"
#import <MediaPlayer/MPNowPlayingInfoCenter.h>
#import <MediaPlayer/MPContentItem.h>
#import <AVFoundation/AVFoundation.h>


#import "Player.h"
#import "PlayerInforTableViewCell.h"
#import "PlayerMenuTableViewController.h"
#import "HistoryViewController.h"
#import "FindViewController.h"
#import "MusicModel.h"

@interface PlayerViewController ()

@property (nonatomic, strong) UISlider *slider;  // 播放进度条
@property (nonatomic, strong) UIButton *nextButton;
@property (nonatomic, strong) UIButton *playButton;
@property (nonatomic, strong) UIButton *forwardButton;
@property (nonatomic, strong) UILabel *totelLabel;
@property (nonatomic, strong) UILabel *nowLabel;
@property (nonatomic, strong) UITableView *tabelView;
@property (nonatomic, strong) UILabel *naviLabel;


@property (nonatomic, strong) UIImageView *bottomImageView;
@property (nonatomic, strong) UIImageView *topImageView;
@property (nonatomic, strong) UIImageView *titelImageView;
@property (nonatomic, strong) UILabel *titelLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UITextView *inforView;

@property (nonatomic, strong) NSDictionary *stricDic;
@property (nonatomic, strong) NSDictionary *albumDic;
@property (nonatomic, strong) NSArray *listArr;
@property (nonatomic, strong) NSMutableArray *arr;
@property (nonatomic, assign) NSInteger num;
@property (nonatomic, assign) NSInteger number;
@property (nonatomic, assign) BOOL direction;
@property (nonatomic, assign) BOOL isSlider;
@property (nonatomic, strong) MusicModel *musicModel;
@property (nonatomic, strong) PlayerModel *playModel;

@end

@implementation PlayerViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // app 远程控制
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
    
    
    self.tabBarController.tabBar.hidden = NO;
    // 状态栏颜色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    self.navigationController.navigationBar.layer.masksToBounds = YES;
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bigShadow.png"] forBarMetrics:UIBarMetricsCompact];
    

}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 结束远程控制
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
    self.navigationController.navigationBar.layer.masksToBounds = NO;
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsCompact];
    

}

- (BOOL)canBecomeFirstResponder
{
    return YES;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    // 播放器
    Player *player = [Player shareInstance];
    if (player.audioPlayer.state == STKAudioPlayerStateReady) {
        
        player.history = YES;
        [player playFromNet];

    }
    self.playModel = player.playerModel;
    self.musicModel = [player.playerModel.musicArray objectAtIndex:player.playerModel.index];
    self.num = player.playerModel.index;
    
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(receiveNotification:) name:@"isPlaying" object:nil];
    
    self.direction = YES;
    self.naviLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 330 * FM_Screen_Pts_Width, 40 * FM_Screen_Pts_Height)];
    _naviLabel.text = _musicModel.title;
    [_naviLabel sizeToFit];
    _naviLabel.textColor = [UIColor whiteColor];

    UIImage *backImage = [UIImage imageNamed:@"btn_back_n@2x.png"];
    backImage = [backImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(barButtonAction:)];
    UIImage *moreImage = [UIImage imageNamed:@"bigShadow.png"];
    moreImage = [moreImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:moreImage style:UIBarButtonItemStylePlain target:self action:nil];

    self.navigationItem.titleView = _naviLabel;
   // 大图片
    self.bottomImageView = [[UIImageView alloc
                             ]initWithFrame:CGRectMake(0, 0, FM_Screen_Width, 320 * FM_Screen_Pts_Height + 64)];
    NSURL *url = [NSURL URLWithString:_musicModel.coverLarge];
    [_bottomImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
    [self.view addSubview:_bottomImageView];
    
    //  创建需要的毛玻璃特效类型
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    //  毛玻璃view 视图
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    //添加到要有毛玻璃特效的控件中
    effectView.frame = _bottomImageView.bounds;
    [_bottomImageView addSubview:effectView];
    //设置模糊透明度
    effectView.alpha = 0.7;
    
    self.topImageView = [[UIImageView alloc]initWithFrame:CGRectMake(FM_Screen_Width / 2 - 80 * FM_Screen_Pts_Width, FM_Screen_Width / 2 - 130 * FM_Screen_Pts_Width + 64, 2 * 80 * FM_Screen_Pts_Width, 2 * 80 * FM_Screen_Pts_Width)];
    [_topImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
    [_bottomImageView addSubview:_topImageView];
    
    // 控制器
    UIView *controlView = [[UIView alloc]initWithFrame:CGRectMake(0, 380 * FM_Screen_Pts_Height, FM_Screen_Width, 60 * FM_Screen_Pts_Height)];
    controlView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:controlView];
    
    // 上一曲
    self.forwardButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _forwardButton.frame = CGRectMake(FM_Screen_Width / 2 - 80 * FM_Screen_Pts_Width, 390 * FM_Screen_Pts_Height, 40 * FM_Screen_Pts_Width, 40 * FM_Screen_Pts_Height);
    if (_num != 0) {
        UIImage *forwardImage = [UIImage imageNamed:@"toolbar_prev_n_p.png"];
        forwardImage = [forwardImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_forwardButton setImage:forwardImage forState:UIControlStateNormal];
        _forwardButton.userInteractionEnabled = YES;
    } else {
        UIImage *forwardImage = [UIImage imageNamed:@"toolbar_prev_h_p.png"];
        forwardImage = [forwardImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_forwardButton setImage:forwardImage forState:UIControlStateNormal];
        _forwardButton.userInteractionEnabled = NO;
    }
    [_forwardButton addTarget:self action:@selector(forwardAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_forwardButton];
    
    // 播放/暂停按钮
    self.playButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _playButton.frame = CGRectMake(FM_Screen_Width / 2 - 20 * FM_Screen_Pts_Width, 390 * FM_Screen_Pts_Height, 40 *FM_Screen_Pts_Height, 40 * FM_Screen_Pts_Height);
    UIImage *playImage = [UIImage imageNamed:@"toolbar_pause_n_p.png"];
    playImage = [playImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [_playButton setImage:playImage forState:UIControlStateNormal];
    
    // 设置边框
    _playButton.layer.masksToBounds = YES;
    _playButton.layer.cornerRadius = 20 * FM_Screen_Pts_Height;
    _playButton.layer.borderWidth = 2;
    _playButton.layer.borderColor = [[UIColor colorWithRed:1.000 green:0.500 blue:0.005 alpha:1.000]CGColor];
    [_playButton addTarget:self action:@selector(pauseded) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_playButton];
    
    // 下一曲按钮
    self.nextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _nextButton.frame = CGRectMake(FM_Screen_Width / 2 + 40 * FM_Screen_Pts_Width, 390 * FM_Screen_Pts_Height, 40 * FM_Screen_Pts_Width, 40 * FM_Screen_Pts_Height);
    
    // 判断是否有下一曲
    if (_num < _listArr.count - 1) {
        UIImage *nextImage = [UIImage imageNamed:@"toolbar_next_n_p.png"];
        nextImage = [nextImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_nextButton setImage:nextImage forState:UIControlStateNormal];
        _nextButton.userInteractionEnabled = YES;
    } else {
        UIImage *nextImage = [UIImage imageNamed:@"toolbar_next_h_p.png"];
        nextImage = [nextImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_nextButton setImage:nextImage forState:UIControlStateNormal];
        _nextButton.userInteractionEnabled = NO;
    }
    
    [_nextButton addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_nextButton];
    
    // 列表
    UIButton *listButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    listButton.frame = CGRectMake(FM_Screen_Width / 2 - 140 * FM_Screen_Pts_Width, 395 * FM_Screen_Pts_Height, 30 * FM_Screen_Pts_Width, 30 * FM_Screen_Pts_Width);
    UIImage *listImage = [UIImage imageNamed:@"iconfont-liebiao@2x.png"];
    listImage = [listImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [listButton setImage:listImage forState:UIControlStateNormal];
    [self.view addSubview:listButton];
    [listButton addTarget:self action:@selector(listButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 历史
    UIButton *historyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    historyButton.frame = CGRectMake(FM_Screen_Width / 2 + 100 * FM_Screen_Pts_Width, 395 * FM_Screen_Pts_Height, 30 * FM_Screen_Pts_Width, 30 * FM_Screen_Pts_Height);
    UIImage *historyImage = [UIImage imageNamed:@"iconfont-lishijilu@2x.png"];
    historyImage = [historyImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [historyButton setImage:historyImage forState:UIControlStateNormal];
    [self.view addSubview:historyButton];
    [historyButton addTarget:self action:@selector(moreBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // slider
    self.slider = [[UISlider alloc]initWithFrame:CGRectMake( 0, 370 * FM_Screen_Pts_Height, FM_Screen_Width, 20 * FM_Screen_Pts_Height)];
    [_slider setThumbImage:[UIImage imageNamed:@"iconfont-iconslider.png"] forState:UIControlStateNormal];
    _slider.minimumTrackTintColor = [UIColor orangeColor];
    _slider.maximumTrackTintColor = [UIColor grayColor];
    [_slider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
    _slider.continuous = YES;
    [self.view addSubview:_slider];
    
    // 总时间
    self.totelLabel = [[UILabel alloc]initWithFrame:CGRectMake(FM_Screen_Width - 50 * FM_Screen_Pts_Width, 350 * FM_Screen_Pts_Height, 50 *FM_Screen_Pts_Width, 20 * FM_Screen_Pts_Height)];
    _totelLabel.font = [UIFont systemFontOfSize:13];
    _totelLabel.textColor = [UIColor whiteColor];
    _totelLabel.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_totelLabel];
    // 当前播放时间
    self.nowLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 350 * FM_Screen_Pts_Height, 50 *FM_Screen_Pts_Width, 20 * FM_Screen_Pts_Height)];
    _nowLabel.font = [UIFont systemFontOfSize:13];
    _nowLabel.textAlignment = NSTextAlignmentRight;
    _nowLabel.textColor = [UIColor whiteColor];
    _nowLabel.backgroundColor = [UIColor clearColor];
    [self.view
     addSubview:_nowLabel];
    
    // 间隔
    UIView *interView = [[UIView alloc]initWithFrame:CGRectMake(0, 440 *FM_Screen_Pts_Height, FM_Screen_Width, 10 * FM_Screen_Pts_Height)];
    interView.backgroundColor = UIColorFromRGB(0xe7e7e7);
    [self.view addSubview:interView];
    
    // 背景
    UIView *inforView = [[UIView alloc]initWithFrame:CGRectMake(0, 450 * FM_Screen_Pts_Height, FM_Screen_Width , FM_Screen_Height - 450 * FM_Screen_Pts_Height - 49)];
    [self.view addSubview:inforView];

    // 图标
    self.titelImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10 * FM_Screen_Pts_Width, 10 * FM_Screen_Pts_Height, 40 * FM_Screen_Pts_Width, 40 * FM_Screen_Pts_Width)];
    _titelImageView.layer.masksToBounds = YES;
    _titelImageView.layer.cornerRadius = 20 * FM_Screen_Pts_Width;
    NSURL *titelImageUrl = [NSURL URLWithString:_playModel.coverSmall];
    [_titelImageView sd_setImageWithURL:titelImageUrl placeholderImage:[UIImage imageNamed:@"small_head_male_default@2x.png"]];
    [inforView addSubview:_titelImageView];
    
    // 标题
    self.titelLabel = [[UILabel alloc]initWithFrame:CGRectMake(60 * FM_Screen_Pts_Width, 15 * FM_Screen_Pts_Height, FM_Screen_Width - 60 * FM_Screen_Pts_Width, 10 * FM_Screen_Pts_Height)];
    _titelLabel.font = [UIFont systemFontOfSize:15];
    _titelLabel.text = _playModel.title;
    [inforView addSubview:_titelLabel];
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(60 * FM_Screen_Pts_Width, 37 * FM_Screen_Pts_Height, FM_Screen_Width - 60 * FM_Screen_Pts_Width, 10 * FM_Screen_Pts_Height)];
    _nameLabel.font = [UIFont boldSystemFontOfSize:13];
    _nameLabel.text = _playModel.nickname;
    [inforView addSubview:_nameLabel];
    
    self.inforView = [[UITextView alloc]initWithFrame:CGRectMake(10 * FM_Screen_Pts_Width, 57 * FM_Screen_Pts_Height, FM_Screen_Width - 20 * FM_Screen_Pts_Width, FM_Screen_Height - 490 * FM_Screen_Pts_Height - 49 - 30 * FM_Screen_Pts_Height)];
    _inforView.editable = NO;
    _inforView.text = _playModel.intro;
    [inforView addSubview:_inforView];
    
    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
    
}

// 收到通知要执行的方法
- (void)receiveNotification:(NSNotification *)noti
{
    
    Player *player = [Player shareInstance];
    if (player.history == NO) {
        PlayerModel *playing = noti.object;
        self.num = playing.index;
        self.playModel = playing;
        self.musicModel = [playing.musicArray objectAtIndex:playing.index];
        NSURL *url = [NSURL URLWithString:_musicModel.coverLarge];
        [_bottomImageView sd_setImageWithURL:url];
        [_topImageView sd_setImageWithURL:url];
        
        _titelLabel.text = playing.title;
        _nameLabel.text = _playModel.nickname;
        
        _inforView.frame = CGRectMake(10 * FM_Screen_Pts_Width, 55 * FM_Screen_Pts_Height, FM_Screen_Width - 20 * FM_Screen_Pts_Width, FM_Screen_Height - 490 * FM_Screen_Pts_Height - 49);
        _inforView.text = _playModel.intro;
        
        NSString *titleImageStr = _playModel.coverSmall;
        NSURL *titleImageUrl = [NSURL URLWithString:titleImageStr];
        [_titelImageView sd_setImageWithURL:titleImageUrl];
        
        _naviLabel.text = _musicModel.title;
        [_naviLabel sizeToFit];
        self.navigationItem.titleView = _naviLabel;
    } else {
        self.number = player.number;
        HistoryModel *historyModel = noti.object;
        NSURL *url = [NSURL URLWithString:historyModel.coverLarge];
        [_bottomImageView sd_setImageWithURL:url];
        [_topImageView sd_setImageWithURL:url];
        
        _titelLabel.text = historyModel.albumTitle;
        _nameLabel.text = historyModel.nickname;
        
        _inforView.frame = CGRectMake(10 * FM_Screen_Pts_Width, 55 * FM_Screen_Pts_Height, FM_Screen_Width - 20 * FM_Screen_Pts_Width, FM_Screen_Height - 490 * FM_Screen_Pts_Height - 49);
        _inforView.text = historyModel.intro;
        
        NSURL *titleImageUrl = [NSURL URLWithString:historyModel.albumCoverSmall];
        [_titelImageView sd_setImageWithURL:titleImageUrl];
        
        _naviLabel.text = historyModel.title;
        [_naviLabel sizeToFit];
        self.navigationItem.titleView = _naviLabel;
    }
    
    if (_num != 0 || _number != 0) {
        UIImage *forwardImage = [UIImage imageNamed:@"toolbar_prev_n_p.png"];
        forwardImage = [forwardImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_forwardButton setImage:forwardImage forState:UIControlStateNormal];
        _forwardButton.userInteractionEnabled = YES;
    } else {
        UIImage *forwardImage = [UIImage imageNamed:@"toolbar_prev_h_p.png"];
        forwardImage = [forwardImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_forwardButton setImage:forwardImage forState:UIControlStateNormal];
        _forwardButton.userInteractionEnabled = NO;
    }

    if (_num < _playModel.musicArray.count - 1 || _number < _playModel.musicArray.count - 1) {
        UIImage *nextImage = [UIImage imageNamed:@"toolbar_next_n_p.png"];
        nextImage = [nextImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_nextButton setImage:nextImage forState:UIControlStateNormal];
        _nextButton.userInteractionEnabled = YES;
    } else {
        UIImage *nextImage = [UIImage imageNamed:@"toolbar_next_h_p.png"];
        nextImage = [nextImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_nextButton setImage:nextImage forState:UIControlStateNormal];
        _nextButton.userInteractionEnabled = NO;
    }

    if (player.audioPlayer.state == STKAudioPlayerStatePlaying) {
        
        UIImage *playImage = [UIImage imageNamed:@"toolbar_pause_n_p.png"];
        playImage = [playImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_playButton setImage:playImage forState:UIControlStateNormal];
    }
    
}

- (void)moreBarButtonAction:(UIBarButtonItem *)bar
{
    
    HistoryViewController *historyVC = [[HistoryViewController alloc]init];
    [self.navigationController pushViewController:historyVC animated:YES];
    
}

- (void)barButtonAction:(UIBarButtonItem *)bar
{
    self.tabBarController.selectedIndex = 0;
}

#pragma mark - 列表
- (void)listButtonAction:(UIButton *)btn
{
    PlayerMenuTableViewController *playerMenuVC = [[PlayerMenuTableViewController alloc]init];
    [self.navigationController pushViewController:playerMenuVC animated:YES];
}

#pragma mark - 暂停/开始
- (void)pauseded
{
    Player *player = [Player shareInstance];
    if (player.audioPlayer.state == STKAudioPlayerStatePaused) {
        [player.audioPlayer resume];
        UIImage *playImage = [UIImage imageNamed:@"toolbar_pause_n_p.png"];
        playImage = [playImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_playButton setImage:playImage forState:UIControlStateNormal];
    } else if (player.audioPlayer.state == STKAudioPlayerStatePlaying) {
        [player.audioPlayer pause];
        UIImage *playImage = [UIImage imageNamed:@"toolbar_play_n_p.png"];
        playImage = [playImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_playButton setImage:playImage forState:UIControlStateNormal];
    }
}

#pragma mark - 下一首
- (void)nextAction:(UIButton *)btn
{
    Player *player = [Player shareInstance];
    if (player.playerModel.musicArray.count != 0) {
        [player collectPreseve];
    }
    [player next];
}

#pragma marl - 上一首
- (void)forwardAction:(UIButton *)btn
{
    
    Player *player = [Player shareInstance];
    if (player.playerModel.musicArray.count != 0) {
        [player collectPreseve];
    }
    [player forward];
}

// slider随播放进度改变
- (void)tick:(NSTimer *)timer
{
    Player *player = [Player shareInstance];
    if (!player.audioPlayer) {
        _slider.value = 0;
    }
    if (player.audioPlayer.currentlyPlayingQueueItemId != nil) {
        _slider.minimumValue = 0;
        _slider.maximumValue = player.audioPlayer.duration;
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        formatter.dateFormat = @"mm:ss";
        NSDate *totelDate = [NSDate dateWithTimeIntervalSince1970:player.audioPlayer.duration];
        NSString *dateStr = [formatter stringFromDate:totelDate];
        _totelLabel.text = dateStr;
        
        _slider.value = player.audioPlayer.progress;
        NSDate *nowDate = [NSDate dateWithTimeIntervalSince1970:player.audioPlayer.progress];
        NSString *nowStr = [formatter stringFromDate:nowDate];
        _nowLabel.text = nowStr;
        
    } else {
        _slider.minimumValue = 0;
        _slider.maximumValue = 0;
        _slider.value = 0;
    }
}
// 进度随slider改变
- (void)sliderChange:(NSTimer *)timer
{
    
    Player *player = [Player shareInstance];
    if (_slider.maximumValue != player.audioPlayer.progress) {
        [player.audioPlayer seekToTime:_slider.value];
    }
}


//section 分区间隔
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return FM_Screen_Pts_Height * 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return FM_Screen_Pts_Height * 80;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

//重写父类方法，接受外部事件的处理
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
    if (receivedEvent.type == UIEventTypeRemoteControl) {
        switch (receivedEvent.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                [self pauseded];
                break;
                
                
            case UIEventSubtypeRemoteControlPreviousTrack:
                 [self forwardAction:nil];
                break;
                
            case UIEventSubtypeRemoteControlNextTrack:
               [self nextAction:nil];
                break;
                
            case UIEventSubtypeRemoteControlPause:
                [self pauseded];
                break;
               case UIEventSubtypeRemoteControlPlay:
                [self pauseded];
                
                break;
                
            default:
                break;
        }
    }
}

@end
